home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / scm / slib / t3.init < prev    next >
Text File  |  1999-04-19  |  13KB  |  428 lines

  1. ;;; "t3.init" Initialization file for SLIB for T3.1.    -*-scheme-*-
  2. ;;; Authors: David Carlton, Stephen Bevan, F. Javier Thayer, and Aubrey Jaffer.
  3. ;;;
  4. ;;; This code is in the public domain.
  5.  
  6. ;;; File has T syntax, and should be compiled in standard-env.
  7. ;;; Compiled file has .so suffix.
  8. ;;; File (or compiled version) should be loaded into scheme-env.
  9.  
  10. ;;; This is provided with ABSOLUTELY NO GUARANTEE.
  11. (herald t3)
  12.  
  13. (define (software-type) 'UNIX)
  14.  
  15. (define (scheme-implementation-type) 'T)
  16.  
  17. (define (scheme-implementation-version) "3.1")
  18.  
  19. ;;; (scheme-implementation-home-page) should return a (string) URL
  20. ;;; (Uniform Resource Locator) for this scheme implementation's home
  21. ;;; page; or false if there isn't one.
  22.  
  23. (define (scheme-implementation-home-page)
  24.   "ftp://ftp.cs.indiana.edu:21/pub/scheme-repository/imp/t/README")
  25.  
  26. ;;; (implementation-vicinity) should be defined to be the pathname of
  27. ;;; the directory where any auxillary files to your Scheme
  28. ;;; implementation reside. It is settable.
  29.  
  30. (define implementation-vicinity
  31.   (make-simple-switch 'implementation-vicinity
  32.               (lambda (x) (or (string? x) (false? x)))
  33.               '#f))
  34. (set (implementation-vicinity) "/usr/local/lib/tsystem/")
  35.  
  36. ;;; (library-vicinity) should be defined to be the pathname of the
  37. ;;; directory where files of Scheme library functions reside. It is settable.
  38.  
  39. (define library-vicinity
  40.   (make-simple-switch 'library-vicinity
  41.               (lambda (x) (or (string? x) (false? x)))
  42.               '#f))
  43. (set (library-vicinity) "/usr/local/lib/slib/")
  44. ;;Obviously put your value here.
  45.  
  46. ;;; (home-vicinity) should return the vicinity of the user's HOME
  47. ;;; directory, the directory which typically contains files which
  48. ;;; customize a computer environment for a user.
  49.  
  50. (define (home-vicinity) #f)
  51.  
  52. ;;; *FEATURES* should be set to a list of symbols describing features
  53. ;;; of this implementation.  See Template.scm for the list of feature
  54. ;;; names.
  55.  
  56. (define *features*
  57.       '(
  58.     source                ;can load scheme source files
  59.                     ;(slib:load-source "filename")
  60.     compiled            ;can load compiled files
  61.                     ;(slib:load-compiled "filename")
  62.     rev3-report
  63.     rev4-optional-procedures
  64.     rev3-procedures
  65.     rev2-procedures
  66.     multiarg/and-
  67.     multiarg-apply
  68.     rationalize
  69.     object-hash
  70.     delay
  71.     i/o-redirection
  72.     char-ready?
  73.     with-file
  74.     transcript
  75.     full-continuation
  76.     pretty-print
  77.     format
  78.     trace                ;has macros: TRACE and UNTRACE
  79.     program-arguments
  80.     ))
  81.  
  82. (define substring
  83.   (let ((primitive-substring (*value standard-env 'substring)))
  84.     (lambda (string start end)
  85.       (primitive-substring string start (max 0 (- end 1))))))
  86.  
  87. ; Modify substring as T's substring takes (start,count) instead of
  88. ; (start,end)
  89.  
  90. (set (syntax-table-entry (env-syntax-table scheme-env) 'require) '#f)
  91.  
  92. ; Turn off the macro REQUIRE so that it can be rebound as a function
  93. ; later.
  94.  
  95. ; extend <, >, <= and >= so that they take more than two arguments.
  96.  
  97. (define <
  98.   (let ((primitive< (*value standard-env '<)))
  99.     (labels ((v (lambda (a b . rest)
  100.           (if (null? rest)
  101.               (primitive< a b)
  102.               (and (primitive< a b)
  103.                (apply v b (car rest) (cdr rest)))))))
  104.         v)))
  105.  
  106. (define >
  107.   (let ((primitive> (*value standard-env '>)))
  108.     (labels ((v (lambda (a b . rest)
  109.           (if (null? rest)
  110.               (primitive> a b)
  111.               (and (primitive> a b)
  112.                (apply v b (car rest) (cdr rest)))))))
  113.         v)))
  114.  
  115. (define <=
  116.   (let ((primitive<= (*value standard-env '<=)))
  117.     (labels ((v (lambda (a b . rest)
  118.           (if (null? rest)
  119.               (primitive<= a b)
  120.               (and (primitive<= a b)
  121.                (apply v b (car rest) (cdr rest)))))))
  122.         v)))
  123.  
  124. (define >=
  125.   (let ((primitive>= (*value standard-env '>=)))
  126.     (labels ((v (lambda (a b . rest)
  127.           (if (null? rest)
  128.               (primitive>= a b)
  129.               (and (primitive>= a b)
  130.                (apply v b (car rest) (cdr rest)))))))
  131.         v)))
  132.  
  133. (define =
  134.   (let ((primitive= (*value standard-env '=)))
  135.     (labels ((v (lambda (a b . rest)
  136.           (if (null? rest)
  137.               (primitive= a b)
  138.               (and (primitive= a b)
  139.                (apply v b (car rest) (cdr rest)))))))
  140.         v)))
  141.  
  142. (define gcd
  143.   (let ((prim (*value standard-env 'gcd)))
  144.     (labels ((v (lambda x
  145.           (cond ((null? x) 0)
  146.             ((= (length x) 1) (car x))
  147.             ('#t (prim (car x) (apply v (cdr x))))))))
  148.         v)))
  149.  
  150. (define list? (*value standard-env 'proper-list?))
  151.  
  152. (define program-arguments command-line)
  153.  
  154. ;;; (OUTPUT-PORT-WIDTH <port>)
  155. (define output-port-width
  156.   (lambda x
  157.     (if (null? x) (line-length (standard-input))
  158.     (line-length (car x)))))
  159.  
  160. ;;; (OUTPUT-PORT-HEIGHT <port>)
  161. (define (output-port-height . arg) 24)
  162.  
  163. ;;; (CURRENT-ERROR-PORT)
  164. (define current-error-port
  165.   (let ((port (current-output-port)))
  166.     (lambda () port)))
  167.  
  168. ;;; (TMPNAM) makes a temporary file name.
  169. (define tmpnam
  170.   (let ((cntr 100))
  171.     (lambda () (set! cntr (+ 1 cntr))
  172.         (let ((tmp (string-append "slib_" (number->string cntr))))
  173.           (if (file-exists? tmp) (tmpnam) tmp)))))
  174.  
  175. (define delete-file file-delete)
  176.  
  177. ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
  178. ;;; be returned by CHAR->INTEGER.
  179. (define char-code-limit 256)
  180.  
  181. ;;; MOST-POSITIVE-FIXNUM is used in modular.scm
  182. ;;; T already has it.
  183.  
  184. ;;; Return argument
  185. (define (identity x) x)
  186.  
  187. ;;; SLIB:EVAL is single argument eval using the top-level (user) environment.
  188. (define (slib:eval form) (eval form scheme-env))
  189.  
  190. ;;; If your implementation provides R4RS macros:
  191. ;(define macro:eval slib:eval)
  192. ;(define macro:load load)
  193.  
  194. (define *defmacros*
  195.   (list (cons 'defmacro
  196.           (lambda (name parms . body)
  197.         `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body))
  198.                       *defmacros*))))))
  199. (define (defmacro? m) (and (assq m *defmacros*) #t))
  200.  
  201. (define (macroexpand-1 e)
  202.   (if (pair? e) (let ((a (car e)))
  203.           (cond ((symbol? a) (set! a (assq a *defmacros*))
  204.                      (if a (apply (cdr a) (cdr e)) e))
  205.             (else e)))
  206.       e))
  207.  
  208. (define (macroexpand e)
  209.   (if (pair? e) (let ((a (car e)))
  210.           (cond ((symbol? a)
  211.              (set! a (assq a *defmacros*))
  212.              (if a (macroexpand (apply (cdr a) (cdr e))) e))
  213.             (else e)))
  214.       e))
  215.  
  216. (define gentemp
  217.   (let ((*gensym-counter* -1))
  218.     (lambda ()
  219.       (set! *gensym-counter* (+ *gensym-counter* 1))
  220.       (string->symbol
  221.        (string-append "slib:G" (number->string *gensym-counter*))))))
  222.  
  223. (define base:eval slib:eval)
  224. (define (defmacro:eval x) (base:eval (defmacro:expand* x)))
  225. (define (defmacro:expand* x)
  226.   (require 'defmacroexpand) (apply defmacro:expand* x '()))
  227.  
  228. (define (defmacro:load <pathname>)
  229.   (slib:eval-load <pathname> defmacro:eval))
  230.  
  231. (define (slib:eval-load <pathname> evl)
  232.   (if (not (file-exists? <pathname>))
  233.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  234.   (call-with-input-file <pathname>
  235.     (lambda (port)
  236.       (let ((old-load-pathname *load-pathname*))
  237.     (set! *load-pathname* <pathname>)
  238.     (do ((o (read port) (read port)))
  239.         ((eof-object? o))
  240.       (evl o))
  241.     (set! *load-pathname* old-load-pathname)))))
  242.  
  243. (define slib:warn
  244.   (lambda args
  245.     (let ((port (current-error-port)))
  246.       (display "Warn: " port)
  247.       (for-each (lambda (x) (display x port)) args))))
  248.  
  249. ;;; define an error procedure for the library
  250. (define slib:error error)
  251.  
  252. ;;; define these as appropriate for your system.
  253. (define slib:tab #\tab)
  254. (define slib:form-feed #\form)
  255.  
  256. ;;; Define these if your implementation's syntax can support it and if
  257. ;;; they are not already defined.
  258.  
  259. ;(define (1+ n) (+ n 1))
  260. (define (1- n) (+ n -1))
  261. ;(define (-1+ n) (+ n -1))
  262.  
  263. (define program-vicinity
  264.   (make-simple-switch 'program-vicinity
  265.               (lambda (x) (or (string? x) (false? x)))
  266.               '#f))
  267.  
  268. (define in-vicinity string-append)
  269.  
  270. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  271. ;;; return if exitting not supported.
  272. (define slib:exit (lambda args (exit))
  273.  
  274. (define (string . args) (apply string-append (map char->string args)))
  275.  
  276. (define make-string
  277.   (let ((t:make-string (*value standard-env 'make-string)))
  278.     (lambda (a . b)
  279.       (let ((str (t:make-string a)))
  280.     (if b (map-string! (lambda (x) (ignore x) (car b)) str) str)))))
  281.  
  282. (define (string>? a b)
  283.   (labels ((aux
  284.         (lambda (n a b)
  285.           ;;start off with n<=(string-length b) and n<=(string-length a)
  286.           ;;a,b coincide for chars <n
  287.           (cond ((= (string-length a) n) (< n (string-length b)))
  288.                     ;;now (< n (string-length a))
  289.             ((= (string-length b) n) '#f)
  290.                     ;;now (< n (string-length a))
  291.             ((char=? (nthchar a n) (nthchar b n) ) (aux (+ 1 n) a b))
  292.             ('#t (char<? (nthchar b n) (nthchar a n)))))))
  293.     (aux 0 a b)))
  294.  
  295. (define (string<? a b) (string>? b a))
  296. (define (string<=? a b) (not (string>? a b)))
  297. (define (string>=? a b) (not (string<? a b)))
  298.  
  299. (define (string-ci<? a b)
  300.   (string<? (string-upcase a) (string-upcase b)))
  301.  
  302. (define (string-ci>? a b)
  303.   (string>? (string-upcase a) (string-upcase b)))
  304.  
  305. (define (string-ci<=? a b)
  306.   (string<=? (string-upcase a) (string-upcase b)))
  307.  
  308. (define (string-ci>=? a b)
  309.   (string>=? (string-upcase a) (string-upcase b)))
  310.  
  311. ;;; FORCE-OUTPUT flushes any pending output on optional arg output port
  312. ;;; use this definition if your system doesn't have such a procedure.
  313. ;;; T already has it, but requires 1 argument.
  314.  
  315. (define force-output
  316.   (let ((t:force-output (*value standard-env 'force-output)))
  317.     (lambda x
  318.       (if x
  319.       (t:force-output (car x))
  320.       (t:force-output (current-output-port))))))
  321.  
  322. ;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
  323. ;;; port versions of CALL-WITH-*PUT-FILE.
  324. (define (call-with-output-string proc)
  325.   (with-output-to-string var (proc var)))
  326.  
  327. (define (call-with-input-string string proc)
  328.   (with-input-from-string (variable string) (proc variable)))
  329.  
  330. (define (string->number s . x)
  331.   (let ((base (if x (car x) 10))
  332.     (s (string-upcase s)))
  333.     (or (mem? = base '(8 10 16))
  334.     (error (format (current-error-port) "Bad radix ~A" base)))
  335.     (if (= (string-length s) 0) '()
  336.     (let ((char->number
  337.            (lambda (ch)
  338.          (cdr (ass char=? ch
  339.                '((#\0 . 0)
  340.                  (#\1 . 1) (#\2 . 2) (#\3 . 3) (#\4 . 4)
  341.                  (#\5 . 5) (#\6 . 6) (#\7 . 7) (#\8 . 8)
  342.                  (#\9 . 9) (#\A . 10) (#\B . 11) (#\C . 12)
  343.                  (#\D . 13) (#\E . 14) (#\F . 15)))))))
  344.       (catch not-num
  345.          (iterate loop ((pos (- (string-length s) 1))
  346.                 (power 1) (accum 0))
  347.               (if (< pos 0) accum
  348.                   (let ((num (char->number (string-ref s pos))))
  349.                 (or num (not-num '()))
  350.                 (or  (< num base) (not-num '()))
  351.                 (loop (- pos 1)
  352.                       (* power base)
  353.                       (+ accum (*  num power)))))))))))
  354.  
  355. (define (number->string n . x)
  356.   (let ((rad (if (car x) (car x) 10)))
  357.     (format nil
  358.         (case rad
  359.           ((8) "~O")
  360.           ((10) "~D")
  361.           ((16) "~X")
  362.           (else (error (format (current-error-port)
  363.                    "Bad radix ~A" (car x)))))
  364.         n)))
  365.  
  366. (define (inexact? f)
  367.   (float? f))
  368.  
  369. (define (exact? f)
  370.   (not (inexact? f)))
  371.  
  372. (define exact->inexact ->float)
  373.  
  374. (define peek-char
  375.   (let ((t:peek-char (*value standard-env 'peek-char)))
  376.     (lambda p
  377.       (let ((port (if p (car p) (current-input-port))))
  378.     (t:peek-char port)))))
  379.  
  380. ;;;(set ((*value scheme-env 'standard-early-binding-env) 'load) '#f)
  381. ;;;(set ((*value scheme-env 'standard-early-binding-env) 'substring) '#f)
  382. (set ((*value scheme-env 'standard-early-binding-env) 'less?) '#f)
  383. (set ((*value scheme-env 'standard-early-binding-env) 'greater?) '#f)
  384. (set ((*value scheme-env 'standard-early-binding-env) 'not-less?) '#f)
  385. (set ((*value scheme-env 'standard-early-binding-env) 'not-greater?) '#f)
  386. (set ((*value scheme-env 'standard-early-binding-env) 'number-equal?) '#f)
  387. (set ((*value scheme-internal-env 'standard-early-binding-env) 'list?) '#f)
  388.  
  389. (set ((*value t-implementation-env 'SOURCE-FILE-EXTENSION)) 'scm)
  390.  
  391. ;;; Here for backward compatability
  392. (define (scheme-file-suffix) "")
  393.  
  394. (define load
  395.   (let ((t:load (*value standard-env 'load)))
  396.     (lambda (filespec . x)
  397.       (apply t:load (->filename filespec) x))))
  398.  
  399. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  400. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  401.  
  402. (define slib:load-source load)
  403.  
  404. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  405. ;;; by compiling "foo.scm" if this implementation can compile files.
  406. ;;; See feature 'COMPILED.
  407.  
  408. (define slib:load-compiled load)
  409.  
  410. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  411.  
  412. (define slib:load slib:load-source)
  413.  
  414. (slib:load (in-vicinity (library-vicinity) "require") scheme-env)
  415.  
  416. ;;;(define scheme-read-table
  417. ;;;  (make-read-table standard-read-table 'modified-read-table))
  418. ;;;
  419. ;;;(set (read-table-entry scheme-read-table '#\#)
  420. ;;;     (lambda  (p ch rtable)
  421. ;;;       (ignore ch) (ignore rtable)
  422. ;;;       ((*value scheme-env 'string->number)
  423. ;;;    (symbol->string (read-refusing-eof p)) 16)))
  424. ;;;
  425. ;;;(set (port-read-table (standard-input)) scheme-read-table)
  426.  
  427. ; eof
  428.